package com.ngc.mall.manager.redis;

import com.ngc.mall.service.ICouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

/**
 *
 * 优惠券过期通知 ,监听redis 10库
 * @author: chenxiaolin
 * @date 2023/10/11 17:47
**/
@Component
public class CouponExpireListener implements MessageListener {
    @Autowired
    private ICouponService iCouponService;
    @Override
    public void onMessage(Message message, byte[] pattern) {
        byte[] body = message.getBody();
        byte[] channel = message.getChannel();

        String expiredKey = new String(body);
        String topic = new String(channel);
        String[] temp=expiredKey.split(",");
        Long cid=Long.valueOf(temp[0]);
        Long uid=Long.valueOf(temp[1]);
        iCouponService.expire(cid,uid);
    }
}
